package com.nate.tasking.actions;

import java.util.List;

import javax.jdo.PersistenceManager;

import org.apache.log4j.Logger;

import com.nate.tasking.data.PMF;
import com.nate.tasking.domain.Project;
import com.opensymphony.xwork2.ActionSupport;

public class ViewProjectAction extends ActionSupport{

	private static final long serialVersionUID = 6390974667995625397L;
	private final Logger logger = Logger.getLogger(ViewProjectAction.class);
	private List<Project> listOfProjects;

	public String execute(){
		logger.debug("View Projects Action");
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
    	try {
    		String query = "select from " + Project.class.getName();
    		listOfProjects = (List<Project>) pm.newQuery(query).execute();
    	    System.out.println("project list size: " + listOfProjects.size());
            logger.debug("retrieved projects");
        } finally {
            pm.close();
        }
		return SUCCESS;
	}

	public List<Project> getListOfProjects() {
		return listOfProjects;
	}

	public void setListOfProjects(List<Project> listOfProjects) {
		this.listOfProjects = listOfProjects;
	}
	
	
}
